package org.thinker.util;

public class PageUtil {

	public static String getPageStr(int pageno, int totalCount){
		
		int startPage = -1;
		int lastPage = -1;
		boolean before = false;
		boolean after = false;
		
		int s1 = (int)(Math.floor((pageno-1)/(double)10));
		
		//System.out.println(s1);
		
		startPage = (s1 * 10) + 1;
		
//		System.out.println("start: " +startPage); 
		
		if(startPage != 1){
			before = true;
		}
		
		lastPage = startPage + 9;
		
//		System.out.println("last: " + lastPage);
		
		int tempLast = (int)( Math.ceil(totalCount / (double)10));
		
		if(tempLast > lastPage){
			after = true;
		}
		
//		System.out.println("tempLast: " + tempLast);
		
		if(tempLast < lastPage){
			lastPage = tempLast;
		}
		
//		System.out.println("last2: " + lastPage);
		
		StringBuffer buffer = new StringBuffer();
		
		if(before){
			buffer.append("<a href='javascript:_list("+(startPage-1)+");'> "+ " < "+" </a>");			
		}
		
		for(int i = startPage; i <= lastPage ; i++){
			buffer.append("<a href='javascript:_list("+i+");'> " + i +"</a> ");
		}
		
		if(after){
			buffer.append("<a href='javascript:_list("+(lastPage+1)+");'> "+ " > "+" </a>");			
		}
		
		
//		System.out.println(buffer);
		
		return buffer.toString();
	}
	
}

